
from scrapys.wudiSpyder.wudiSpyder.items import MatchInfoItem, JingcaiSpfGameItem, JingcaiBqcGameItem, \
    JingcaiTtgGameItem, JingcaiCrsGameItem, ZucaiTtgGameItem, ZucaiSfcGameItem, ZucaiBqcGameItem, UpZucaiSfcGameItem, \
    UpZucaiTtgGameItem, UpZucaiBqcGameItem, SportteryMatchItem, OddsSportteryMatchItem, SportteryBasketBallMatchItem, \
    OddsSportteryBasketBallMatchItem, HistoryOddsSportteryMatchItem, HistoryScoreSportteryMatchItem, \
    ResultSportteryMatchItem
import pymysql
'''
处理500万网的足球比赛数据
'''
#   负责500wan及时比分页面的数据保存
class FootballResultPipeline:
        def __init__(self, host, database, user, password, port,batch_size):
            self.host = host
            self.database = database
            self.user = user
            self.password = password
            self.port = port
            self.batch_size = batch_size
            self.match_batch = []
            self.zucai_sfc_batch = []
            self.up_zucai_sfc_batch = []
            self.zucai_ttg_batch = []
            self.up_zucai_ttg_batch = []
            self.zucai_bqc_batch = []
            self.up_zucai_bqc_batch = []
            # 其他初始化代码...

        def process_item(self, item, spider):
            if isinstance(item, MatchInfoItem):
                self.match_batch.append(item)
            elif isinstance(item, ZucaiSfcGameItem):
                self.zucai_sfc_batch.append(item)
            elif isinstance(item, ZucaiTtgGameItem):
                self.zucai_ttg_batch.append(item)
            elif isinstance(item, ZucaiBqcGameItem):
                self.zucai_bqc_batch.append(item)
            elif isinstance(item, UpZucaiSfcGameItem):
                self.up_zucai_sfc_batch.append(item)
            elif isinstance(item, UpZucaiTtgGameItem):
                self.up_zucai_ttg_batch.append(item)
            elif isinstance(item, UpZucaiBqcGameItem):
                self.up_zucai_bqc_batch.append(item)

            if len(self.match_batch) >= self.batch_size or\
                    len(self.zucai_sfc_batch) >= self.batch_size or \
                    len(self.up_zucai_sfc_batch) >= self.batch_size or \
                    len(self.zucai_ttg_batch) >= self.batch_size or \
                    len(self.up_zucai_ttg_batch) >= self.batch_size or \
                    len(self.zucai_bqc_batch) >= self.batch_size or \
                    len(self.up_zucai_bqc_batch) >= self.batch_size:
                self._flush_batches()

            return item

        @classmethod
        def from_crawler(cls, crawler):
            return cls(
                host = crawler.settings.get('MYSQL_HOST'),
                database = crawler.settings.get('MYSQL_DATABASE'),
                user = crawler.settings.get('MYSQL_USER'),
                password = crawler.settings.get('MYSQL_PASSWORD'),
                port = crawler.settings.get('MYSQL_PORT'),
                batch_size =crawler.settings.get('MYSQL_BATCH_SIZE'),

            )

        def open_spider(self, spider):
            self.connection = pymysql.connect(
                host=self.host,
                user=self.user,
                password=self.password,
                database=self.database,
                port=self.port,
                charset='utf8mb4',
                cursorclass=pymysql.cursors.DictCursor
            )
            self.cursor = self.connection.cursor()

        def close_spider(self, spider):
            self._flush_batches()
            # 其他清理代码...
            self.connection.close()

        # 保存胜负彩信息
        def save_football_game_zucai_sfc_batch(self):
            # 处理游戏批次
            if self.zucai_sfc_batch:
                values = []
                for item in self.zucai_sfc_batch:
                    values.append((
                        item['game_no'],
                        item['result'],
                        item['fid'],
                        item['expect']
                    ))
                sql = """insert into spider_lottery_football_game_zucai_sfc (game_no, result, fid, expect) 
                VALUES (%s, %s, %s, %s) ON DUPLICATE KEY UPDATE 
                result = VALUES(result)"""

                self.cursor.executemany(
                    sql,
                    values
                )
                self.zucai_sfc_batch = []

            # 更新停售时间游戏批次
            if self.up_zucai_sfc_batch:
                up_values = []
                for item in self.up_zucai_sfc_batch:
                    up_values.append((
                        item['stop_time'],
                        item['expect']
                    ))

                self.cursor.executemany(
                    """UPDATE spider_lottery_football_game_zucai_sfc set stop_time = %s where expect = %s""",
                    up_values
                )
                self.up_zucai_sfc_batch = []


        # 保存4场进球信息
        def save_football_game_zucai_bqc_batch(self):
            # 处理游戏批次
            if self.zucai_bqc_batch:
                values = []
                for item in self.zucai_bqc_batch:
                    values.append((
                        item['game_no'],
                        item['result'],
                        item['fid'],
                        item['expect']
                    ))
                sql = """insert into spider_lottery_football_game_zucai_bqc (game_no, result, fid, expect) 
                VALUES (%s, %s, %s, %s) ON DUPLICATE KEY UPDATE 
                result = VALUES(result)"""

                self.cursor.executemany(
                    sql,
                    values
                )
                self.zucai_bqc_batch = []

            # 更新停售时间游戏批次
            if self.up_zucai_bqc_batch:
                up_values = []
                for item in self.up_zucai_bqc_batch:
                    up_values.append((
                        item['stop_time'],
                        item['expect']
                    ))

                self.cursor.executemany(
                    """UPDATE spider_lottery_football_game_zucai_bqc set stop_time = %s where expect = %s""",
                    up_values
                )
                self.up_zucai_bqc_batch = []



        # 保存4场进球信息
        def save_football_game_zucai_ttg_batch(self):
            # 处理游戏批次
            if self.zucai_ttg_batch:
                values = []
                for item in self.zucai_ttg_batch:
                    values.append((
                        item['game_no'],
                        item['result'],
                        item['fid'],
                        item['expect']
                    ))
                sql = """insert into spider_lottery_football_game_zucai_ttg (game_no, result, fid, expect) 
                VALUES (%s, %s, %s, %s) ON DUPLICATE KEY UPDATE 
                result = VALUES(result)"""
                self.cursor.executemany(
                    sql,
                    values
                )
                self.zucai_ttg_batch = []

            # 更新停售时间游戏批次
            if self.up_zucai_ttg_batch:
                up_values = []
                for item in self.up_zucai_ttg_batch:
                    up_values.append((
                        item['stop_time'],
                        item['expect']
                    ))

                self.cursor.executemany(
                    """UPDATE spider_lottery_football_game_zucai_ttg set stop_time = %s where expect = %s""",
                    up_values
                )
                self.up_zucai_ttg_batch = []

        # 保存比赛基本信息
        def save_match_batch(self):
            # 处理比赛批次
            if self.match_batch:
                match_values = []
                for match_item in self.match_batch:
                    match_values.append((
                        match_item['fid'],
                        match_item['match_status'],
                        match_item['contest'],
                        match_item['match_time'],
                        match_item['match_round'],
                        match_item['home_team'],
                        match_item['home_team_ranking'],
                        match_item['home_team_url'],
                        match_item['match_line'],
                        match_item['away_team'],
                        match_item['away_team_ranking'],
                        match_item['away_team_url'],
                        match_item['odds'],

                        match_item['home_team_half_score'],
                        match_item['away_team_half_score'],
                        match_item['home_team_score'],
                        match_item['away_team_score']
                    ))

                match_sql = """INSERT INTO spider_lottery_football_match_500wan 
                                    (fid, match_status, contest, match_time,match_round,home_team,
                                    home_team_ranking,home_team_url,match_line,away_team,away_team_ranking,
                                    away_team_url,odds,home_team_half_score,away_team_half_score,home_team_score,away_team_score) 
                                    VALUES (%s, %s, %s, %s,%s, %s, %s, %s, %s, %s,%s, %s, %s, %s,%s, %s, %s)
                                    ON DUPLICATE KEY UPDATE
                                    match_status = VALUES(match_status),
                                    match_time = VALUES(match_time),
                                    match_line = VALUES(match_line),
                                    odds = VALUES(odds),
                                    home_team_half_score = VALUES(home_team_half_score),
                                    away_team_half_score = VALUES(away_team_half_score),
                                    home_team_score = VALUES(home_team_score),
                                    away_team_score = VALUES(away_team_score)"""
                self.cursor.executemany(
                    match_sql,
                    match_values
                )
                self.match_batch = []

        def _flush_batches(self):
            try:
                self.connection.begin()
                self.save_match_batch()
                self.save_football_game_zucai_sfc_batch()
                self.save_football_game_zucai_ttg_batch()
                self.save_football_game_zucai_bqc_batch()
                self.connection.commit()
            except Exception as e:
                self.connection.rollback()
                raise




#   负责500wan选购页面的竞猜数据保存
class FootballJingcaiPipeline:
        def __init__(self, host, database, user, password, port,batch_size):
            self.host = host
            self.database = database
            self.user = user
            self.password = password
            self.port = port
            self.batch_size = batch_size
            self.spf_game_batch = []
            self.bqc_game_batch = []
            self.ttg_game_batch = []
            self.crs_game_batch = []
            # 其他初始化代码...

        def process_item(self, item, spider):
            if isinstance(item, JingcaiSpfGameItem):
                print("胜平负：",item)
                self.spf_game_batch.append(item)
            elif isinstance(item, JingcaiBqcGameItem):
                self.bqc_game_batch.append(item)
            elif isinstance(item, JingcaiTtgGameItem):
                self.ttg_game_batch.append(item)
            elif isinstance(item, JingcaiCrsGameItem):
                self.crs_game_batch.append(item)

            if len(self.spf_game_batch) >= self.batch_size or\
                    len(self.bqc_game_batch) >= self.batch_size or \
                    len(self.ttg_game_batch) >= self.batch_size or \
                    len(self.crs_game_batch) >= self.batch_size:
                self._flush_batches()

            return item

        @classmethod
        def from_crawler(cls, crawler):
            return cls(
                host = crawler.settings.get('MYSQL_HOST'),
                database = crawler.settings.get('MYSQL_DATABASE'),
                user = crawler.settings.get('MYSQL_USER'),
                password = crawler.settings.get('MYSQL_PASSWORD'),
                port = crawler.settings.get('MYSQL_PORT'),
                batch_size =crawler.settings.get('MYSQL_BATCH_SIZE'),

            )

        def open_spider(self, spider):
            self.connection = pymysql.connect(
                host=self.host,
                user=self.user,
                password=self.password,
                database=self.database,
                port=self.port,
                charset='utf8mb4',
                cursorclass=pymysql.cursors.DictCursor
            )
            self.cursor = self.connection.cursor()

        def close_spider(self, spider):
            self._flush_batches()
            # 其他清理代码...
            self.connection.close()

        # 保存竞猜胜平负游戏信息
        def save_spf_game_batch(self):
            # 处理游戏批次
            if self.spf_game_batch:
                spf_game_values = []
                for game_item in self.spf_game_batch:
                    spf_game_values.append((
                        game_item['fid'],
                        game_item['expect'],
                        game_item['stop_time'],
                        game_item['game_no'],
                        game_item['game_no_num'],
                        game_item['rang_qiu'],
                        game_item['spf_single'],
                        game_item['rspf_single'],
                        game_item['spf_bonus'],
                        game_item['rspf_bonus'],
                    ))
                self.cursor.executemany(
                    """INSERT INTO spider_lottery_football_game_jingcai 
                    (fid,expect, stop_time, game_no,game_no_num,rang_qiu,spf_single,rspf_single,spf_bonus,rspf_bonus) 
                    VALUES (%s,%s, %s, %s,%s,%s, %s, %s,%s,%s)
                    ON DUPLICATE KEY UPDATE
                    rang_qiu = VALUES(rang_qiu),
                    spf_single = VALUES(spf_s),
                    rspf_single = VALUES(spf_p),
                    spf_bonus = VALUES(spf_f),
                    rspf_bonus = VALUES(rang_spf_s)""",
                    spf_game_values
                )

                self.spf_game_batch = []

        # 保存竞猜-总进球游戏信息
        def save_ttg_game_batch(self):
            # 处理游戏批次
            if self.ttg_game_batch:
                ttg_game_values = []
                for game_item in self.ttg_game_batch:
                    ttg_game_values.append((
                        game_item['fid'],
                        game_item['expect'],
                        game_item['stop_time'],
                        game_item['game_no'],
                        game_item['game_no_num'],
                        game_item['ttg_bonus'],
                    ))

                self.cursor.executemany(
                    """INSERT INTO spider_lottery_football_game_jingcai
                    (fid, expect, fid, expect,stop_time,game_no,game_no_num,ttg_bonus) 
                    VALUES (%s, %s, %s, %s,%s, %s, %s, %s)
                    ON DUPLICATE KEY UPDATE
                    ttg_bonus = VALUES(ttg_bonus)""",
                    ttg_game_values
                )
                self.ttg_game_batch = []

        # 保存竞猜-半全场游戏信息
        def save_bqc_game_batch(self):
            # 处理游戏批次
            if self.bqc_game_batch:
                bqc_game_values = []
                for game_item in self.bqc_game_batch:
                    bqc_game_values.append((
                        game_item['fid'],
                        game_item['expect'],
                        game_item['stop_time'],
                        game_item['game_no'],
                        game_item['game_no_num'],
                        game_item['bqc_bonus'],
                    ))

                self.cursor.executemany(
                    """INSERT INTO spider_lottery_football_game_jingcai 
                                        (fid, expect, fid, expect,stop_time,game_no,game_no_num,bqc_bonus) 
                                        VALUES (%s, %s, %s, %s,%s, %s, %s, %s)
                                        ON DUPLICATE KEY UPDATE
                                        bqc_bonus = VALUES(bqc_bonus)""",
                    bqc_game_values
                )
                self.bqc_game_batch = []

        # 保存竞猜-比分游戏信息
        def save_crs_game_batch(self):
            # 处理游戏批次
            if self.crs_game_batch:
                crs_game_values = []
                for game_item in self.crs_game_batch:
                    crs_game_values.append((
                        game_item['fid'],
                        game_item['expect'],
                        game_item['stop_time'],
                        game_item['game_no'],
                        game_item['game_no_num'],
                        game_item['crs_bonus']
                    ))

                self.cursor.executemany(
                    """INSERT INTO spider_lottery_football_game_jingcai
                                        (fid, expect, fid, expect,stop_time,game_no,game_no_num,crs_bonus) 
                                        VALUES (%s, %s, %s, %s,%s, %s, %s, %s)
                                        ON DUPLICATE KEY UPDATE
                                        crs_bonus = VALUES(crs_bonus)""",
                    crs_game_values
                )
                self.crs_game_batch = []

        def _flush_batches(self):

            try:
                self.connection.begin()
                self.save_spf_game_batch()
                self.save_bqc_game_batch()
                self.save_ttg_game_batch()
                self.save_crs_game_batch()
                self.connection.commit()
            except Exception as e:
                self.connection.rollback()
                raise



#   负责中国竞猜网的竞猜数据保存
class SportteryPipeline:
        def __init__(self, host, database, user, password, port,batch_size):
            self.host = host
            self.database = database
            self.user = user
            self.password = password
            self.port = port
            self.batch_size = batch_size
            self.match_batch = []
            self.odds_batch = []
            self.his_odds_batch = []
            self.score_batch = []
            self.result_batch = []
            # 其他初始化代码...

        def process_item(self, item, spider):
            if isinstance(item, SportteryMatchItem):
                self.match_batch.append(item)
            elif isinstance(item, OddsSportteryMatchItem):
                self.odds_batch.append(item)
            elif isinstance(item, HistoryOddsSportteryMatchItem):
                self.his_odds_batch.append(item)
            elif isinstance(item, HistoryScoreSportteryMatchItem):
                self.score_batch.append(item)
            elif isinstance(item, ResultSportteryMatchItem):
                self.result_batch.append(item)

            if len(self.match_batch) >= self.batch_size or\
                    len(self.odds_batch) >= self.batch_size or \
                    len(self.his_odds_batch) >= self.batch_size or \
                    len(self.score_batch) >= self.batch_size or \
                    len(self.result_batch) >= self.batch_size:
                self._flush_batches()

            return item

        @classmethod
        def from_crawler(cls, crawler):
            return cls(
                host = crawler.settings.get('MYSQL_HOST'),
                database = crawler.settings.get('MYSQL_DATABASE'),
                user = crawler.settings.get('MYSQL_USER'),
                password = crawler.settings.get('MYSQL_PASSWORD'),
                port = crawler.settings.get('MYSQL_PORT'),
                batch_size =crawler.settings.get('MYSQL_BATCH_SIZE'),

            )

        def open_spider(self, spider):
            self.connection = pymysql.connect(
                host=self.host,
                user=self.user,
                password=self.password,
                database=self.database,
                port=self.port,
                charset='utf8mb4',
                cursorclass=pymysql.cursors.DictCursor
            )
            self.cursor = self.connection.cursor()

        def close_spider(self, spider):
            self._flush_batches()
            # 其他清理代码...
            self.connection.close()

        # 保存竞猜比赛信息
        def save_match_batch(self):
            print("保存比赛：",len(self.match_batch))
            if self.match_batch:
                values = []
                for match_item in self.match_batch:
                    values.append((
                        match_item['matchId'],
                        match_item['businessDate'],
                        match_item['homeTeamAbbName'],
                        match_item['homeTeamId'],
                        match_item['awayTeamAbbName'],
                        match_item['awayTeamId'],
                        match_item['leagueAbbBackColor'],
                        match_item['leagueAbbName'],
                        match_item['matchDate'],
                        match_item['matchNum'],
                        match_item['matchNumStr'],
                        match_item['matchStatus'],
                        match_item['matchTime'],
                        match_item['sellStatus']
                    ))
                self.cursor.executemany(
                    """INSERT INTO spider_lottery_football_match_sporttery 
                    (match_id,business_date, home_team_abb_name, home_team_id,away_team_abb_name,away_team_id,league_abb_back_color,league_abb_name,match_date,match_num,match_num_str,match_status,match_time,sell_status) 
                    VALUES (%s,%s, %s, %s,%s,%s, %s, %s, %s,%s,%s,%s,%s,%s)
                    ON DUPLICATE KEY UPDATE
                    match_status = VALUES(match_status),
                    match_time = VALUES(match_time),
                    sell_status = VALUES(sell_status)""",
                    values
                )

                self.match_batch = []

        # 更新竞猜-游戏奖金信息
        def save_odds_batch(self):
            print("保存足球奖金：",len(self.odds_batch))
            if self.odds_batch:
                values = []
                for odd_item in self.odds_batch:
                    values.append((
                        odd_item["spf_bonus"],
                        odd_item["rspf_bonus"],
                        odd_item["ttg_bonus"],
                        odd_item["bqc_bonus"],
                        odd_item["crs_bonus"],
                        odd_item["spf_single"],
                        odd_item["rspf_single"],
                        odd_item["goalLine"],

                        odd_item["matchId"],
                    ))
                #      ,match_result_list = %s,sections_no999 = %s,single_list = %s,crs_list = %s,had_list = %s,hafu_list = %s,hhad_list = %s,ttg_list = %s
                self.cursor.executemany(
                        """UPDATE spider_lottery_football_match_sporttery 
                        set spf_bonus = %s,rspf_bonus = %s,ttg_bonus = %s,bqc_bonus = %s,crs_bonus = %s,spf_single = %s,rspf_single = %s,goal_line = %s
                           where match_id = %s""",
                        values
                    )
                self.odds_batch = []


        # 更新竞猜-游戏历史奖金信息
        def save_his_odds_batch(self):
            print("保存历史奖金：",len(self.his_odds_batch))
            if self.his_odds_batch:
                values = []
                for odd_item in self.his_odds_batch:
                    values.append((
                        odd_item["spf_bonus"],
                        odd_item["rspf_bonus"],
                        odd_item["ttg_bonus"],
                        odd_item["bqc_bonus"],
                        odd_item["crs_bonus"],
                        odd_item["spf_single"],
                        odd_item["rspf_single"],
                        odd_item["goalLine"],
                        odd_item["matchStatus"],
                        odd_item["sellStatus"],

                        # odd_item["crsList"],
                        # odd_item["hadList"],
                        # odd_item["hafuList"],
                        # odd_item["hhadList"],
                        # odd_item["ttgList"],

                        odd_item["matchId"],
                    ))
                # ,match_result_list = %s,crs_list = %s,had_list = %s,hafu_list = %s,hhad_list = %s,ttg_list = %s
                self.cursor.executemany(
                        """UPDATE spider_lottery_football_match_sporttery 
                        set spf_bonus = %s,rspf_bonus = %s,ttg_bonus = %s,bqc_bonus = %s,crs_bonus = %s,spf_single = %s,rspf_single = %s,goal_line = %s,match_status=%s,sell_status=%s
                        where match_id = %s""",
                        values
                )
                self.his_odds_batch = []


        # 更新竞猜-比赛比分
        def update_score_batch(self):
            print("更新竞猜比赛比分：",len(self.score_batch))
            if self.score_batch:
                values = []
                for item in self.score_batch:
                    values.append((
                        item["sectionsNo1"],
                        item["sectionsNo999"],
                        item["matchId"]
                    ))
                self.cursor.executemany(
                        """UPDATE spider_lottery_football_match_sporttery 
                        set sections_no1=%s,sections_no999=%s
                        where match_id = %s""",
                        values
                )
                self.score_batch = []

        # 更新竞猜-比赛开奖结果
        def update_result_batch(self):
            print("更新竞猜比赛开奖结果：",len(self.result_batch))
            if self.result_batch:
                values = []
                for item in self.result_batch:
                    values.append((
                        item["matchResultList"],
                        item["matchId"]
                    ))
                self.cursor.executemany(
                        """UPDATE spider_lottery_football_match_sporttery 
                        set match_result_list=%s
                        where match_id = %s""",
                        values
                )
                self.result_batch = []


        def _flush_batches(self):
            try:
                self.connection.begin()
                self.save_match_batch()
                self.save_odds_batch()
                self.save_his_odds_batch()
                self.update_score_batch()
                self.update_result_batch()
                self.connection.commit()
            except Exception as e:
                self.connection.rollback()
                raise



#   负责中国竞猜网的篮球竞猜数据保存
# class SportteryBasketballPipeline:
#         def __init__(self, host, database, user, password, port,batch_size):
#             self.host = host
#             self.database = database
#             self.user = user
#             self.password = password
#             self.port = port
#             self.batch_size = batch_size
#             self.match_batch = []
#             self.odds_batch = []
#             # 其他初始化代码...
#
#         def process_item(self, item, spider):
#             if isinstance(item, SportteryBasketBallMatchItem):
#                 self.match_batch.append(item)
#             elif isinstance(item, OddsSportteryBasketBallMatchItem):
#                 self.odds_batch.append(item)
#
#             if len(self.match_batch) >= self.batch_size or\
#                     len(self.odds_batch) >= self.batch_size:
#                 self._flush_batches()
#
#             return item
#
#         @classmethod
#         def from_crawler(cls, crawler):
#             return cls(
#                 host = crawler.settings.get('MYSQL_HOST'),
#                 database = crawler.settings.get('MYSQL_DATABASE'),
#                 user = crawler.settings.get('MYSQL_USER'),
#                 password = crawler.settings.get('MYSQL_PASSWORD'),
#                 port = crawler.settings.get('MYSQL_PORT'),
#                 batch_size =crawler.settings.get('MYSQL_BATCH_SIZE'),
#
#             )
#
#         def open_spider(self, spider):
#             self.connection = pymysql.connect(
#                 host=self.host,
#                 user=self.user,
#                 password=self.password,
#                 database=self.database,
#                 port=self.port,
#                 charset='utf8mb4',
#                 cursorclass=pymysql.cursors.DictCursor
#             )
#             self.cursor = self.connection.cursor()
#
#         def close_spider(self, spider):
#             self._flush_batches()
#             # 其他清理代码...
#             self.connection.close()
#
#         # 保存竞猜比赛信息
#         def save_match_batch(self):
#             print("保存比赛：",len(self.match_batch))
#             if self.match_batch:
#                 values = []
#                 for match_item in self.match_batch:
#                     values.append((
#                         match_item['matchId'],
#                         match_item['businessDate'],
#                         match_item['homeTeamAbbName'],
#                         match_item['homeTeamId'],
#                         match_item['awayTeamAbbName'],
#                         match_item['awayTeamId'],
                        #leagueAbbBackColor
#                         match_item['leagueAbbName'],
#                         match_item['matchDate'],
#                         match_item['matchNumStr'],
#                         match_item['matchStatus'],
#                         match_item['matchTime'],
#                         match_item['sellStatus']
#                     ))
#                 self.cursor.executemany(
#                     """INSERT INTO spider_lottery_basketball_match_sporttery
#                     (match_id,business_date, home_team_abb_name, home_team_id,away_team_abb_name,away_team_id,league_abb_name,match_date,match_numStr,match_status,match_time,sell_status)
#                     VALUES (%s,%s, %s, %s,%s,%s,%s,%s,%s,%s,%s,%s)
#                     ON DUPLICATE KEY UPDATE
#                     match_status = VALUES(matchStatus),
#                     match_time = VALUES(matchTime),
#                     sell_status = VALUES(sellStatus)""",
#                     values
#                 )
#
#                 self.match_batch = []
#
#         # 更新竞猜-游戏奖金信息
#         def save_odds_batch(self):
#             print("保存篮球奖金：",len(self.odds_batch))
#             if self.odds_batch:
#                 values = []
#                 for odd_item in self.odds_batch:
#                     values.append((
#                         odd_item["sf_bonus"],
#                         odd_item["rsf_bonus"],
#                         odd_item["dx_bonus"],
#                         odd_item["wnm_bonus"],
#                         odd_item["single"],
#                         odd_item["dxLine"],
#                         odd_item["goalLine"],
#                         odd_item['matchNum'],
#                         odd_item["matchId"]
#                     ))
#                 self.cursor.executemany(
#                         """UPDATE spider_lottery_basketball_match_sporttery
#                         set sf_bonus = %s,rsf_bonus = %s,dx_bonus = %s,wnm_bonus = %s,single = %s,dxLine = %s,goalLine = %s,matchNum=%s where matchId = %s""",
#                         values
#                  )
#                 self.odds_batch = []
#
#
#
#         def _flush_batches(self):
#             try:
#                 self.connection.begin()
#                 self.save_match_batch()
#                 self.save_odds_batch()
#                 self.connection.commit()
#             except Exception as e:
#                 self.connection.rollback()
#                 raise
#
#
#
